package com.shire.shire_interface.controller.clientversion;

import com.shire.shire_interface.service.clientversion.ClientVersionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

@Controller
@RequestMapping("/clientver")
public class ClientVersionController {
    @Resource
    private ClientVersionService clientVersionService;

    @RequestMapping("/versionManager")
    public ModelAndView versionManager(){
        ModelAndView view = new ModelAndView("clientver/clientver");
        return view;
    }

//    @RequestMapping(value = "/versionManager", method = RequestMethod.POST)
//    public String onUpload(MultipartFile file) throws IOException{
//        ClientVersion clientVersion = new ClientVersion();
//        clientVersion.setStatus(Constants.CommonStatus.DISABLE.ordinal());
//        String oriName = file.getOriginalFilename();
//        clientVersion.setOriname(oriName);
//        clientVersion.setFilesize((int)file.getSize());
//        // 设置版本 jerryinfo-v100.deb
//        int lastDot = oriName.lastIndexOf(".");
//        int lastSplit = oriName.lastIndexOf("-");
//        if(lastSplit<0 || lastSplit>=lastDot-2){
//            clientVersion.setVersion(-1);
//        }
//        else{
//            String verStr = oriName.substring(lastSplit+2, lastDot);
//            clientVersion.setVersion(StrUtils.getIntValue(verStr, -2));
//        }
//
//        File path = new File(ResourceUtils.getURL("classpath:").getPath());
//        if (!path.exists()) {
//            path = new File("");
//        }
//
//        String targetDir = "clientversion";
//
//        String dirPath = "static" + File.separator + targetDir + File.separator;
//        File upload = new File(path.getAbsolutePath(), dirPath);
//        if (!upload.exists()) {
//            boolean mkdirs = upload.mkdirs();
//        }
//        String newFileName = System.currentTimeMillis() + "-" + oriName;
//        File uploadFile = new File(path.getAbsolutePath(), dirPath + newFileName);
//
//        org.apache.commons.io.FileUtils.copyInputStreamToFile(file.getInputStream(), uploadFile);
//
//        clientVersion.setFilepath(targetDir+File.separator+newFileName);
//        clientVersion.setCreatetime(new Date());
//        clientVersion.setUpdatetime(new Date());
//        clientVersionService.insertClientVersion(clientVersion);
//
//        return "/clientver/clientver";
//    }
}
